package com.heima.behavior.listen;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.ApFollowBehaviorService;
import com.heima.common.constants.message.FollowBehaviorConstants;
import com.heima.model.behavior.dtos.FollowBehaviorDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.KafkaListener;

import javax.annotation.Resource;

@Configuration
@Slf4j
public class FollowBehaviorListener {

    @Resource
    ApFollowBehaviorService apFollowBehaviorService;

    @KafkaListener(topics = FollowBehaviorConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void followBehaviorListener(String message) {
        if (StringUtils.isNotBlank(message)) {
            log.info("FollowBehaviorListener receiverMessage：{}", message);
            apFollowBehaviorService.saveFollowBehavior(JSON.parseObject(message, FollowBehaviorDto.class));
            log.info("FollowBehaviorListener success");
        }

    }
}
